/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MyTimePanel.java
 *
 * Created on 28.4.2011, 18:25:43
 */

package forms;

import forms.Alert;
import java.awt.Color;
import java.awt.ComponentOrientation;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import javax.swing.JLabel;
import src.CasADatum;
import src.Evidence;
import src.TimeCompare;

/**
 *
 * @author Viktor
 */
public class MyTimePanel extends javax.swing.JPanel implements Runnable {
//     Date datum;
    JLabel tlb;
    DateFormat fDateFormat = null;
     SimpleDateFormat hodiny = null;
     SimpleDateFormat minuty = null;
     SimpleDateFormat denVT= null;
    Date ted ;
     private Thread v;
      Calendar cal ;
         Alert a = null;
         Evidence e;
         TimeCompare tc;
         
    /** Creates new form MyTimePanel */

     
    public MyTimePanel(Evidence e) {
        initComponents();
        setSize(1000,50);
        this.e=e;
//        JLabel tlb = new JLabel();
//        add(tlb);
//        tlb.setText("Ahoj");
//        tlb.setForeground(Color.green);
       // tc = new TimeCompare(e);
      cal = new GregorianCalendar();
         fDateFormat = DateFormat.getTimeInstance(DateFormat.DEFAULT);
//         hodiny = DateFormat.getTimeInstance(DateFormat.SHORT);
         hodiny = new SimpleDateFormat("HH");       //form. retezec pro hodiny
         minuty = new SimpleDateFormat("mm") ;      // minuty
         denVT = new SimpleDateFormat("EEE") ;      //den v tydnu
//         minuty = DateFormat.getTimeInstance(DateFormat.MINUTE_FIELD);
         v = new Thread(this,"Time");
         v.start();
         TimeLabel.setText("ČAS");
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        TimeLabel = new javax.swing.JLabel();
        DOWLabel = new javax.swing.JLabel();
        DnesLabel = new javax.swing.JLabel();

        setBackground(new java.awt.Color(204, 204, 255));
        setMaximumSize(new java.awt.Dimension(32767, 50));
        setMinimumSize(new java.awt.Dimension(1000, 50));
        setPreferredSize(new java.awt.Dimension(1000, 50));

        TimeLabel.setFont(new java.awt.Font("Verdana", 1, 18));
        TimeLabel.setForeground(new java.awt.Color(0, 204, 51));
        TimeLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        TimeLabel.setText("<TIME>");

        DOWLabel.setFont(new java.awt.Font("Tahoma", 1, 14));
        DOWLabel.setText("<DOW>");

        DnesLabel.setFont(new java.awt.Font("Tahoma", 1, 14));
        DnesLabel.setText("Dnes je : ");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(614, Short.MAX_VALUE)
                .addComponent(DnesLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(26, 26, 26)
                .addComponent(DOWLabel)
                .addGap(40, 40, 40)
                .addComponent(TimeLabel)
                .addGap(28, 28, 28))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(TimeLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(DOWLabel)
                    .addComponent(DnesLabel))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    public void run() {
        boolean zobrazeno = false;
while(true){
         ted = new Date();
        String date_out = fDateFormat.format (ted);
        tc = new TimeCompare(e);  
        //TODO: Udělat všechno přes Date a nahradit Calendary
        TimeLabel.setText(date_out);
       
        DOWLabel.setText(CasADatum.DenVTydnu(cal.get(Calendar.DAY_OF_WEEK)));
       
        DnesLabel.setText("Dnes je " + cal.get(Calendar.DAY_OF_MONTH) + ". " + (cal.get(Calendar.MONTH)+1) + ". " + cal.get(Calendar.YEAR));
//        int hodina = cal.get(Calendar.HOUR_OF_DAY) ;
//        int minuta = cal.get(Calendar.MINUTE);
        int day = cal.get(Calendar.DAY_OF_WEEK);
        
        String hours = hodiny.format(ted);
        String minutes = minuty.format(ted);
        int hodina = Integer.parseInt(hours);
        int minuta = Integer.parseInt(minutes);
//        int hodina = Integer.parseInt(hours);
//        int minuta =  Integer.parseInt(minutes);
       
       
       tc.compare(hodina, minuta, day); 
//        if((hodina == 23) &&( minuta ==40) && !zobrazeno){
//            a = new Alert();
//            a.setVisible(true);
//            
//          zobrazeno = true;
//        }
       }
    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel DOWLabel;
    private javax.swing.JLabel DnesLabel;
    private javax.swing.JLabel TimeLabel;
    // End of variables declaration//GEN-END:variables
private String porovnejDenVTydnu(int dow){
    String retval = "";
    switch(dow){
        case 2 : retval = "Pondělí"; break;
        case 3 : retval = "Úterý"; break;
        case 4 : retval = "Středa"; break;
        case 5 : retval = "Čtvrtek"; break;
        case 6 : retval = "Pátek"; break;
        case 0 : retval = "Sobota"; break;
        case 1 : retval = "Neděle"; break;
    }
    return retval;
}
    
}
